<template>
  <div class="search">

    <!-- 主要显示的导航栏 -->
    <div class="block">
      <ul class="block_ul">
        <li
          class="block_li"
          v-for="(item,index) in cityList"
          :key="index"
          @mouseenter="show(index)"
          @mouseleave="hide(index)"
        ><span>{{item.type}}</span><i>></i>
        </li>
      </ul>
      <!-- 隐藏的导航栏 -->
      <div
        class="none"
        v-show="isShow"
        @mouseenter="noneShow"
        @mouseleave="noneHide"
      >
        <ul class="none_ul">
          <li
            class="none_li"
            v-for="(v,i) in noneList.children"
            :key="i"
            @click="sendCity(v.city)"
          >
            <i><a href="#">{{i+1}}</a></i><span><a href="#">{{v.city}}</a></span>
            <p><a href="#">{{v.desc}}</a></p>
          </li>
        </ul>
      </div>
    </div>

  </div>
</template>

<script>
import { recCity } from "@/api/post";
export default {
  data() {
    return {
      isShow: false,
      noneList: [],
      cityList: [],
      liIndex: 0,
    };
  },
  methods: {
    sendCity(val) {
      this.$emit("asideSend", val);
    },
    noneShow() {
      this.isShow = true;
      document.querySelectorAll(".block_ul>.block_li")[
        this.liIndex
      ].style.borderRight = 0;
      document.querySelectorAll(".block_ul>.block_li")[
        this.liIndex
      ].style.color = "#ffa500";
    },
    noneHide() {
      this.isShow = false;
      document.querySelectorAll(".block_ul>.block_li")[
        this.liIndex
      ].style.borderRight = "1px solid #ddd";
      document.querySelectorAll(".block_ul>.block_li")[
        this.liIndex
      ].style.color = "#000000";
    },
    show(i) {
      this.liIndex = i;
      this.isShow = true;
      this.noneList = this.cityList[i];
      document.querySelectorAll(".block_ul>.block_li")[i].style.borderRight = 0;
      document.querySelectorAll(".block_ul>.block_li")[i].style.color =
        "#ffa500";
    },
    hide(i) {
      this.isShow = false;
      document.querySelectorAll(".block_ul>.block_li")[i].style.borderRight =
        "1px solid #ddd";
      document.querySelectorAll(".block_ul>.block_li")[i].style.color =
        "#000000";
    },
  },
  async created() {
    let res = await recCity();
    if (res) {
      this.cityList = res.data.data;
    }
  },
};
</script>

<style lang="less" scoped>
.search {
  position: relative;
  width: 220px;
  // 左侧显示的界面
  .block {
    width: 100%;
    .block_ul {
      width: 100%;
      .block_li {
        z-index: 2;
        font-size: 14px;
        margin-top: -1px;
        padding: 0 20px;
        width: 100%;
        height: 39px;
        border: 1px solid #dddddd;
        display: flex;
        justify-content: space-between;
        align-items: center;
        i {
          font-family: "宋体";
        }
      }
    }
    // 右侧隐藏的界面
    .none {
      position: absolute;
      right: -42px;
      top: 0px;
      width: 343px;
      height: 200px;
      transform: translate(100%, 0);
      border: 1px solid #dddddd;
      border-left: 0;
      background-color: white;
      z-index: 1;

      .none_ul {
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
        width: 100%;
        display: flex;
        flex-direction: column;
        li:nth-child(5) {
          border-left: 1px solid #dddddd;
        }
        .none_li {
          width: 100%;
          height: 40px;
          padding: 0 20px;
          display: flex;
          align-items: center;
          i {
            font-family: "宋体";
            font-size: 24px;
            font-weight: 500;
            color: #ffa500;
            margin-right: 15px;
          }
          span {
            color: #ffa500;
            margin-right: 15px;
            font-size: 14px;
          }
          p {
            font-size: 12px;
          }
        }
      }
    }
  }
}
</style>